// SH_PluginsUI

require("datastream")


if SERVER then

	AddCSLuaFile("autorun/SH_PluginsUI.lua")

	concommand.Add("ChatBot_Plugins_UI", function( pl, cmd, args)
		umsg.Start("ChatBot_Plugins_UI", pl )
		umsg.End()
		for k,v in pairs( ChatBot.Plugins ) do
			datastream.StreamToClients( pl, "ChatBot_Plugins_UI_DATASTREAM", { k , v["Name"], v["Info"] , v["Usage"], v["Category"] } );
		end
	end)
	
	
else

	usermessage.Hook( "ChatBot_Plugins_UI" , function( um )
	
		local TableOfPlugins = { }
		
		local DermaPanel = vgui.Create( "DFrame" )
		DermaPanel:SetSize( 1000, 700 )
		DermaPanel:SetTitle( "ChatBot : Plugins GUI" )
		DermaPanel:SetVisible( true )
		DermaPanel:SetDraggable( true )
		DermaPanel:ShowCloseButton( true )
		DermaPanel:MakePopup()
		DermaPanel:Center()
		 
		local DermaListView = vgui.Create("DListView")
		DermaListView:SetParent(DermaPanel)
		DermaListView:SetPos(5, 27)
		DermaListView:SetSize(990, 500) // Y was 625, now 500 . 625 - 500 = 125 . 125 - 2 * 5 = 115
		DermaListView:SetMultiSelect(false)
		DermaListView:AddColumn("Name")
		DermaListView:AddColumn("Information")
		DermaListView:AddColumn("Usage")
		DermaListView:AddColumn("Category")
		
		local button = vgui.Create( "DButton", DermaPanel )
		button:SetSize( 100, 30 )
		button:SetPos( 450, 700 - 115 / 2  )
		button:SetText( "Reload Plugins" )
		button.DoClick = function()
			if LocalPlayer():IsAdmin() then
				LocalPlayer():ConCommand("ChatBot_ReloadPlugins")
			end
		end

		
		datastream.Hook( "ChatBot_Plugins_UI_DATASTREAM", function( handler, id, encoded, decoded )
			
			DermaListView:AddLine(decoded[2],decoded[3],decoded[4],decoded[5])
			
		end)
		
		
	end)

end

